<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">  
 <%--  <%@include file="../../common/taglib.jsp"%>
  <%@include file="../../common/lte.jsp"%> --%>
  <title>商户后台</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />

<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">商户后台登录</p>

    <form action="${baseURL }/index" method="post">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" placeholder="手机号" name="mobile" id="mobile" value="${mobile }"/>
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" placeholder="密 码" name="password" value="${password }"/>
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <c:if test="${codeStatus=='ACTIVE'}">
      	<div class="form-group has-feedback clearfix">
	      <div class="col-xs-7" style="padding:0;">
	        <input type="code" class="form-control" placeholder="验证码" name="code" value="${code }"/>
	        <span class="glyphicon glyphicon-phone form-control-feedback"></span>
	      </div>
        <button type="button" id="setCode" class="btn btn-primary btn-flat col-xs-5">发送短信</button>
      </div>
      </c:if>
      
      <div class="form-group has-feedback" style="display: none;" id="login_msg">
        <span style="color: red;" id="msg">${msg }</span> 
      </div>
      <div class="row">
        
        <!-- /.col -->
        <div class="col-xs-12">
          <button type="submit" class="btn btn-primary btn-block btn-flat">登 录</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
	
    

  </div>
  <!-- /.login-box-body -->
</div>
<script>
var msg = '${msg}';
if(msg != ''){
	$("#login_msg").show();
}else{
	$("#login_msg").hide();
}
  $(function () {
    
    var setCodeinterval;
    $("#setCode").on("click",function(){
    	var that = $(this);
    	if(that.hasClass("btn-primary")){
    		sendSms(that);
    	}
    })
    
  });
  
  function sendSms(that){
	  var mobile = $("#mobile").val();
	  $.ajax({  
	        type: "POST",
	        data:{mobile : mobile},
	        dataType : "json",
	        url: "${baseURL }/sendSms",
	        success: function(result){
	        	if(result.code == '0'){
	        		alertMsg("验证码已成功发送至"+mobile,"success");
	        		var num = 60;
	        		that.removeClass("btn-primary").text(num + "s");
	        		setCodeinterval = setInterval(function(){
	        			num -- ;
	        			if(num < 0 ){
	        				that.text("重新发送").addClass("btn-primary");
	        				clearInterval(setCodeinterval);
	        			}else{
	                		that.text(num + "s");
	        			}
	        		},1000)
	        	}else{
	        		alertMsg(result.msg,"danger");
	        	}
	        	
	        },  
	        error : function() {
	        	alertMsg("系统异常！","danger");
	        }   
	    });
  }
</script>
</body>
</html>